package org.example.everyday;

import java.util.Map;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/6/7 9:55
 */
public class Lc875 {
    public static void main(String[] args) {
        Lc875 lc875 = new Lc875();

        int[] piles = new int[]{3,6,7,11};
        int h = 8;
        int res = lc875.minEatingSpeed(piles,h);
        System.out.println(res);
    }

    public int minEatingSpeed(int[] piles, int h) {
        int low = 1;
        int high = 0;
        for(int pile : piles){
            high = Math.max(high,pile);
        }
        int k = high;
        while (low < high){
            int speed = (high - low) / 2 + low;
            long time = getTime(piles,speed);
            if(time <= h){
                k = speed;
                high = speed;
            } else {
                low = speed + 1;
            }
        }
        return k;
    }

    private long getTime(int[] piles, int speed) {
        long time = 0;
        for(int pile : piles){
            int curTime = (pile + speed - 1) / speed;
            time += curTime;
        }
        return time;
    }
}
